<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use EasyWeChat\Work\Application;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class WxworkController extends Controller
{
    //
    public function index(Request $request)
    {



        Log::info('request arrived.');
        Log::info($request->all());

        $server = app('easywechat.work')->getServer();

//        $message = $server->getRequestMessage();
//        Log::info(json_encode($message));
        $decMessage = $server->getDecryptedMessage(); //解密消息
        Log::info(json_encode($decMessage));
        Http::post('https://f.tjcu.edu.cn/api/workflow/hooks/Njg5MWIzMjFjMTA0ZDczYzE4NTg4MTQ5',$decMessage);

//        $server->with(function($message){
//            return "欢迎关注 overtrue！";
//        });

        return $server->serve();


        $config = [
            'corp_id' => 'wx7e0220e77a488538',
            'secret' => 'pLVcaVsHj9MAlbRY6gRSpTvDVh-R0vdYE_IPDzQG2_A',
            'token' => '672c8d16411c47b0a43f34d667098985',
            'aes_key' => '4d1e625476904ae18cf2ef0f6f367ad51c95885b5b7',
            // 记得配置suite_id，不然suite_ticket不能自动存储
            'suite_id' => 'ww9f1388bf664xxxxx',
            'suite_secret' => 'reuXvCX_5FhDVm_sOslJEHRVxxxxxxx',

        ];
        $app = new Application($config);
        $server = $app->getServer();
//        return $server->serve();
        $message = $server->getRequestMessage(); // 原始消息
//        $decMessage = $server->getDecryptedMessage(); //解密消息
        Log::info(json_encode($message));
//        Log::info(json_encode($decMessage));
        return $server->serve();
    }
}
